const baseUrl = `${window.location.origin}/`;
layui.use(['element','form','table','layer','laydate'], function () {
    var table = layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var laydate = layui.laydate;
    $ = layui.jquery;

    //执行一个laydate实例
    laydate.render({
        elem: '#beginDate' //指定元素
        ,type: 'datetime'
    });
    laydate.render({
        elem: '#endDate' //指定元素
        ,type: 'datetime'
    });
    // 巡检人员
    loadStaffList();

    table.render({
        elem: '#itemTable'
        ,cellMinWidth: 80
        ,method: 'get'
        ,url: baseUrl+'/insStatistics/list'
        ,title: '巡检结果统计'
        ,toolbar: '#toolbarDemo'
        ,page: true
        ,cols: [[
            {type: 'checkbox', fixed: 'left'}
            ,{type:'numbers',title:'序号'}
            ,{field:'staff', title:'巡检人员', align:'center'}
            ,{field:'inspectCount', title:'巡检次数', align:'center'}
            ,{field:'totalInspectDur', title:'累计巡检时长', align:'center'}
            ,{field:'firstInspectTime', title:'第一次巡检日期', align:'center'}
            ,{field:'latestInspectTime', title:'最近一次巡检日期', align:'center'}
            // ,{field:'right', title:'操作', align:'center',templet:
            //         function (data) {
            //             return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn  layui-btn-normal layui-btn-xs" lay-event="detail">查看</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>'
            //         }}
        ]]
    });

    form.on('submit(search)',function (data) {
        table.reload('itemTable', {
            page: {
                curr: 1
            },
            where: {
                staffId: $('#staffSelect').val(),
                startTime: $("#beginDate").val(),
                endTime: $("#endDate").val()
            }
        }, 'data');
        return false;
    });

    active = {
        reload: function(){
            //执行重载
            table.reload('itemTable', {});
        }
    }
    function loadStaffList(){
        $.get(baseUrl+'/insTask/getStaffList', {}, function (result) {
            //result.data = [{"id":"1","name":"张麻子"}, {"id":"2","name":"小鬼子"}, {"id":"3","name":"二狗子"}];
            if(result != null){
                if(result.data != null){
                    var a$opt_html = "<option  value=''>全部</option>";
                    $.each(result.data, function (index, item) {
                        a$opt_html += "<option value='" + item.id + "'>" + item.name + "</option>";
                    });
                    $("#staffSelect").empty().append(a$opt_html);
                    form.render('select');

                }
            }
        });
    }

});

function reload(){
    $("#beginDate").val("");
    $("#endDate").val("");
    location.reload();
}